home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 June / MacFormat 25.iso / Shareware City / Developers / macgzip_03b2-src / macos / think / MacAE.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-05  |  2.4 KB  |  122 lines  |  [TEXT/ttxt]

  1. /*
  2.  * MacAE.c, (C) SPDsoft
  3.  * 1994, MacGzip 0.3
  4.  */
  5.  
  6. #include <AppleEvents.h>
  7. #include "MacAE.h"
  8. #include "ThePrefs.h"
  9. #include "MacErrors.h"
  10.  
  11. extern    KeyMap    theKeys;
  12. Boolean StartupFiles = true;
  13.  
  14.  
  15. /* in MacGzip.c */
  16. extern OSErr    DoOpen( FSSpec *myFSSpec );
  17. extern void        MyBeep(void);
  18.  
  19.  
  20.  
  21. OSErr MyGotRequiredParams (AppleEvent *theAppleEvent)
  22. {
  23.     DescType    returnedType;
  24.     Size    actualSize;
  25.     OSErr    err;
  26.  
  27.     err = AEGetAttributePtr (theAppleEvent, keyMissedKeywordAttr,
  28.                                     typeWildCard, &returnedType, nil, 0,
  29.                                     &actualSize);
  30.     if (err == errAEDescNotFound)    // you got all the required parameters
  31.             return noErr;
  32.     else if (!err)                // you missed a required parameter
  33.             return errAEEventNotHandled;
  34.     else                        // the call to AEGetAttributePtr failed
  35.             return err;
  36. }
  37.  
  38.  
  39. /******************************************************************************/
  40. /* Standard AE */
  41.  
  42. pascal OSErr  MyHandleODoc (AppleEvent *theAppleEvent, AppleEvent* reply, long
  43.                                                         handlerRefCon)
  44. {
  45.     FSSpec        myFSS;
  46.     AEDescList    docList;
  47.     OSErr        err, res;
  48.     long        index,
  49.                 itemsInList;
  50.     Size        actualSize;
  51.     AEKeyword    keywd;
  52.     DescType    returnedType;
  53.  
  54.     err = AEGetParamDesc (theAppleEvent, keyDirectObject, typeAEList,
  55.             &docList);
  56.     if (err)
  57.             return err;
  58.  
  59.     err = MyGotRequiredParams (theAppleEvent);
  60.     if (err)
  61.             return err;
  62.  
  63.     err = AECountItems (&docList, &itemsInList);
  64.  
  65.     GetKeys(theKeys);
  66.     
  67.     for (index = 1, res=0; index <= itemsInList; index++) {
  68.  
  69.             err = AEGetNthPtr (&docList, index, typeFSS, &keywd,
  70.                     &returnedType, (Ptr) &myFSS, sizeof(myFSS), &actualSize);
  71.             if (err)
  72.                     return err;
  73.  
  74.             res += (GzipOK!=DoOpen(&myFSS));
  75.     }
  76.  
  77.     err = AEDisposeDesc (&docList);
  78.     
  79.     if ((0==res) && (currPrefs.BeepWhenDone)) MyBeep();
  80.     
  81.     return res;
  82. }
  83.  
  84. pascal OSErr  MyHandlePDoc (AppleEvent *theAppleEvent, AppleEvent *reply, long
  85.                                                         handlerRefCon)
  86. {
  87.     /* can't print by now */
  88.     return ( errAEEventNotHandled );
  89. }
  90.  
  91. pascal OSErr  MyHandleOApp (AppleEvent *theAppleEvent, AppleEvent *reply, long
  92.                                                         handlerRefCon)
  93. {
  94.     OSErr    err;
  95.  
  96.     StartupFiles = false;
  97.     
  98.     if ( err = MyGotRequiredParams (theAppleEvent))
  99.             return err;
  100.     return ( noErr );
  101. }
  102.  
  103.  
  104. pascal    OSErr    MyHandleQuit (AppleEvent *theAppleEvent, AppleEvent *reply,
  105.                     long handlerRefcon)
  106. {
  107.     OSErr    err;
  108.     extern Boolean quitting;
  109.     
  110.     if (err = MyGotRequiredParams(theAppleEvent)) {
  111.         // an error occurred:  do the necessary error handling
  112.         return    err;
  113.     }
  114.     
  115.     /* we should cleanup here */
  116.     
  117.     quitting = true;
  118.     
  119.     return ( noErr );
  120. }
  121.  
  122.